﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace ClassAdd
{
    class ModelClassDescription
    {
        

        public void writeClass(String className, String nameSpace, String pathToWrite, String pathToTemplate, String listOfVaiables, String tableName)
        {

            Directory.CreateDirectory(pathToWrite + "\\Models\\" + className);
            String maskString = File.ReadAllText(pathToTemplate + "\\Models\\EditModel.txt");         
            try
            {
                maskString = maskString.Replace("TABLENAME", tableName);
                maskString = maskString.Replace("VARIABLES", listOfVaiables);
                maskString = maskString.Replace("MASK", className);
                maskString = maskString.Replace("NAMESPACE", nameSpace);
                string className1 = char.ToLower(className[0]) + className.Substring(1, className.Length - 1);
                maskString = maskString.Replace("mask", className1);

                File.WriteAllText(pathToWrite + "\\Models\\" + className + "\\" + className + "EditModel.cs", maskString);                
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            Directory.CreateDirectory(pathToWrite + "\\Models\\" + className);
            String maskString2 = File.ReadAllText(pathToTemplate + "\\Models\\ViewModel.txt");

            try
            {
                maskString2 = maskString2.Replace("TABLENAME", tableName);
                maskString2 = maskString2.Replace("NAMESPACE", nameSpace);
                File.WriteAllText(pathToWrite + "\\Models\\" + className + "\\" + className + "ViewModel.cs", maskString2.Replace("MASK", className));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }
}
